
/*
 *
 * All Rights Reserved.
 */
package com.model.demo.designmodel.strategy.promotion;

import java.util.HashMap;
import java.util.Map;

/**
 * PromotionFactory 注册式单例（容器）+工厂+策略
 *
 * @author Liao Dongshan, 2019年06月11日
 *
 */
public class PromotionFactory {
    private PromotionFactory(){};
    private static final PromotionStrategy NONE_PROMOTION=new NoPromotionStrategy();
    private static Map<String,PromotionStrategy> strategyMap=new HashMap<>();
    static {
        strategyMap.put(PromotionKey.CASHBACK,new CashbackStrategy());
        strategyMap.put(PromotionKey.COUPON,new CouponStrategy());
        strategyMap.put(PromotionKey.GROUPBUY,new GroupBuyStrategy());

    }
    public static PromotionStrategy getPromotionStrategy(String promotionKey){
        return strategyMap.get(promotionKey)==null?NONE_PROMOTION:strategyMap.get(promotionKey);
    }

     interface PromotionKey{
        String COUPON="COUPON";
        String CASHBACK="CASHBACK";
        String GROUPBUY="GROUPBUY";

    }
}
